package cn.iocoder.yudao.module.biz.dal.mysql.risk.hazardResource;

import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.module.biz.controller.admin.risk.hazardResource.vo.BizHazardResourceExportReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.risk.hazardResource.vo.BizHazardResourcePageReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.risk.hazardResource.vo.BizHazardResourceRespVO;
import cn.iocoder.yudao.module.biz.dal.dataobject.risk.hazardResource.BizHazardResourceDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 危险源 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface BizHazardResourceMapper extends BaseMapperX<BizHazardResourceDO> {

    default PageResult<BizHazardResourceDO> selectPage(BizHazardResourcePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BizHazardResourceDO>()
                .eqIfPresent(BizHazardResourceDO::getRiskId,reqVO.getRiskId())
                .eqIfPresent(BizHazardResourceDO::getOperationSteps, reqVO.getOperationSteps())
                .eqIfPresent(BizHazardResourceDO::getHazardEvent, reqVO.getHazardEvent())
                .eqIfPresent(BizHazardResourceDO::getMainConsequences, reqVO.getMainConsequences())
                .eqIfPresent(BizHazardResourceDO::getHazardClassify, reqVO.getHazardClassify())
                .eqIfPresent(BizHazardResourceDO::getPersonLiable, reqVO.getPersonLiable())
                .eqIfPresent(BizHazardResourceDO::getBusinessUnit, reqVO.getBusinessUnit())
                .eqIfPresent(BizHazardResourceDO::getRemarks, reqVO.getRemarks())
                .orderByDesc(BizHazardResourceDO::getId));
    }

    default List<BizHazardResourceDO> selectList(BizHazardResourceExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BizHazardResourceDO>()
                .eqIfPresent(BizHazardResourceDO::getRiskId,reqVO.getRiskId())
                .eqIfPresent(BizHazardResourceDO::getOperationSteps, reqVO.getOperationSteps())
                .eqIfPresent(BizHazardResourceDO::getHazardEvent, reqVO.getHazardEvent())
                .eqIfPresent(BizHazardResourceDO::getMainConsequences, reqVO.getMainConsequences())
                .eqIfPresent(BizHazardResourceDO::getHazardClassify, reqVO.getHazardClassify())
                .eqIfPresent(BizHazardResourceDO::getPersonLiable, reqVO.getPersonLiable())
                .eqIfPresent(BizHazardResourceDO::getBusinessUnit, reqVO.getBusinessUnit())
                .eqIfPresent(BizHazardResourceDO::getRemarks, reqVO.getRemarks())
                .orderByDesc(BizHazardResourceDO::getId));
    }

    @Select("SELECT r.*,d.label risk_level_name FROM biz_hazard_resource r\n" +
            "LEFT JOIN (SELECT value,label FROM system_dict_data WHERE dict_type='risk_level') d\n" +
            "ON r.risk_level = d.value\n" +
            "WHERE r.risk_id = #{riskId}")
    List<BizHazardResourceRespVO> getHazardResourceByRiskId(String riskId);
}
